package com.example.vo;

import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooKeeper;

import java.util.concurrent.TimeUnit;

public class Java7Tester {




    public static void main(String args[])throws Exception{
        // 创建一个与服务器的连接
        ZooKeeper zk = new ZooKeeper("127.0.0.1:2181",3000,new Watcher() {
            @Override
            public void process(WatchedEvent event) {
                // 事件状态为SyncConnected时，说明与服务端的连接已建立好
                System.out.println("事件状态:" + event.getState() +",事件类型:" +  event.getType() +",事件涉及路径:" + event.getPath());
                if (event.getState() == Event.KeeperState.SyncConnected){
                    if (event.getType() == Event.EventType.None && null == event.getPath()){
                        System.out.println("服务器 链接 成功");
                    }
                }else{
                    System.out.println("与服务器断开了链接");
                }
            }
        });
        // 创建一个目录节点
        zk.getChildren("/testRootPath", new Watcher() {
            @Override
            public void process(WatchedEvent watchedEvent) {
                try {
                    zk.getChildren("/testRootPath",this);
                } catch (Exception e) {
                }
                System.out.println("java7"+watchedEvent.getType());
            }
        });
        TimeUnit.SECONDS.sleep(100000);
    }






}
